<html>
<head>
    <title>urlrewrite sample</title>
    <style>
        pre 
        {
            background-color: eeeeee
        }
    </style>
</head>
<body>
    <h2>
        urlrewrite</h2>
    <p>
        This sample demonstrates the use of IIS URL rewrite module to redirect an entire
        branch of the URL namespace to a single node.js application. This mechanism allows
        more control over the URL structure of a node.js web service as well as removes
        the *.js file name from the URL.</p>
    visit the endpoint at <a href="myapp/foo/bar/baz">myapp/foo/bar/baz</a><br />
    visit the endpoint at <a href="myapp/1/2/3?param=4">myapp/1/2/3?param=4</a><br />
    debug the hello.js application at <a href="hello.js/debug" target="_blank">hello.js/debug</a> (requires WebKit enabled browser)<br />
    <p>
        <b>code</b></p>
    <pre>var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('Hello from urlrewrite sample. Request path: ' + req.url);
}).listen(process.env.PORT);</pre>
    <p>
        <b>web.config</b></p>
    <pre>&lt;configuration&gt;
  &lt;system.webServer&gt;

    &lt;!-- indicates that the hello.js file is a node.js application 
    to be handled by the iisnode module --&gt;

    &lt;handlers&gt;
      &lt;add name="iisnode" path="hello.js" verb="*" modules="iisnode" /&gt;
    &lt;/handlers&gt;

    &lt;!-- use URL rewriting to redirect the entire branch of the URL namespace
    to hello.js node.js application; for example, the following URLs will 
    all be handled by hello.js:
    
        http://localhost/node/urlrewrite/myapp
        http://localhost/node/urlrewrite/myapp/foo
        http://localhost/node/urlrewrite/myapp/foo/bar/baz?param=bat
        
    --&gt;
    
    &lt;rewrite&gt;
      &lt;rules&gt;
        &lt;rule name="myapp"&gt;
          &lt;match url="myapp/*" /&gt;
          &lt;action type="Rewrite" url="hello.js" /&gt;
        &lt;/rule&gt;
      &lt;/rules&gt;
    &lt;/rewrite&gt;

  &lt;/system.webServer&gt;
&lt;/configuration&gt;</pre>
</body>
</html>
